package com.ruoyi.bysj.controller;

import com.ruoyi.bysj.domain.SysEvaluation;
import com.ruoyi.bysj.domain.SysOrder;
import com.ruoyi.bysj.domain.SysPay;
import com.ruoyi.bysj.service.ISysEvaluationService;
import com.ruoyi.bysj.service.ISysOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bysj/order2")
public class SysOrderUserController extends BaseController
{
    @Autowired
    private ISysOrderService sysOrderService;

    @Autowired
    private ISysEvaluationService sysEvaluationService;

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:order2:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOrder sysOrder)
    {
        startPage();
        sysOrder.setAppointmentName(getUsername());
        List<SysOrder> list = sysOrderService.selectSysOrderList(sysOrder);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('bysj:order2:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(sysOrderService.selectSysOrderByOrderId(orderId));
    }

    /**
     * 新增评价
     */
    @PreAuthorize("@ss.hasPermi('bysj:order2:add')")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysEvaluation sysEvaluation)
    {
        sysEvaluation.setEvaluationName(getUsername());
        return toAjax(sysEvaluationService.insertSysEvaluation(sysEvaluation));
    }


    @PreAuthorize("@ss.hasPermi('bysj:order2:pay')")
    @Log(title = "支付订单", businessType = BusinessType.UPDATE)
    @PutMapping("/pay")
    public AjaxResult pay(@RequestBody SysPay sysPay)
    {
        sysPay.setPayName(getUsername());
        return toAjax(sysOrderService.updateSysPay(sysPay));
    }
}
